class Solution {
public:
    vector<int> countBits(int n) {
        vector<int> v(n+1, 0);
        for(int i = 1; i <= n; ++i)
        {
            int cnt = 0, tmp = i;
            while(tmp)
            {
                tmp &= (tmp - 1);
                ++cnt;
            }
            v[i] = cnt;
        }
        return v;
    }
};